<script>
  function add_notes(count){
    $('#'+count).fadeIn("slow");
  }
</script>

<div class="main-content">
  <header>
    <h2>Orders</h2>
  </header>

  <section>
    <?php echo $this->renderPartial('/partials/_notifications'); ?>

    <h3>Waiting Orders</h3>
		<table class="datatable paginate sortable full">
			<thead>
				<tr>
          <th>Name</th>
          <th>Address</th>
          <th>Phone</th>
					<th>Quantity</th>
				</tr>
			</thead>
			<tbody>
        <?php $count = 0; ?>
				<?php foreach ($orders as $order){ ?>
        
        <?php 
          $break = false;
          $quantity = 0;
          
          foreach ($order->detail_orders as $detail){
            if($detail->status == Orders::STATUS_PENDING){ 
              $break = true; 
              $quantity = $detail->quantity + $quantity;
            }
          }
          
          if($break){
        ?>
        
				<tr>
					<td align="center"><a href="<?php echo bu('admin/orders/'.$order->id); ?>"><?php echo $order->name; ?></a></td>
          <td align="center"><?php echo $order->address; ?></td>
          <td align="center"><?php echo $order->phone; ?></td>
          <td align="center"><?php echo $quantity; ?></td>
				</tr>
				<?php }} ?>
			</tbody>
		</table>
    
    <h3>Approved Orders</h3>
		<table class="datatable paginate sortable full">
			<thead>
				<tr>
          <th>Name</th>
          <th>Address</th>
          <th>Phone</th>
					<th>Quantity</th>
				</tr>
			</thead>
			<tbody>
        <?php $count = 0; ?>
				<?php foreach ($orders as $order){ ?>
        
        <?php 
          $break = false;
          $quantity = 0;
          
          foreach ($order->detail_orders as $detail){
            if($detail->status == Orders::STATUS_PENDING){ 
              $break = true; 
            }
            else{ $quantity = $detail->quantity + $quantity; }
          }
          
          if(!$break){
        ?>
        
				<tr>
					<td align="center"><a href="<?php echo bu('admin/orders/'.$order->id); ?>"><?php echo $order->name; ?></a></td>
          <td align="center"><?php echo $order->address; ?></td>
          <td align="center"><?php echo $order->phone; ?></td>
          <td align="center"><?php echo $quantity; ?></td>
				</tr>
				<?php }} ?>
			</tbody>
		</table>
  </section>
</div>